import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
// export const useUserInfo=defineStore('模块名',()=>{可以理解成setup函数},{配制})
// vuex持久化：vuex-persistedstate    plugin   persistedstate({paths:['模块名.字段名']})
// pinia持久化：pinia-plugin-persistedstate
//  main.js  import persistedstate from 'pinia-plugin-persistedstate'
//    app.use(createPinia().use(persistedstate))
// { persist：true, 当前模块全部持久化 persist:{paths:['user']}  }
export const useUserInfo = defineStore(
  'userInfo',
  () => {
    // state
    const user = ref({
      name: '张三',
      age: 18
    })
    const stateNum = ref(0)
    // getters
    const getName = computed(() => {
      return '姓名:' + user.value.name
    })
    // actions
    const setName = () => {
      user.value.name = '李四'
    }
    return { user, getName, setName, stateNum }
  },
  {
    persist: {
      paths: ['stateNum']
    }
  }
)
